import { NButton } from 'naive-ui'
export interface Operate {
  name: string
  i18nkey?: string
  type?: 'default' | 'tertiary' | 'primary' | 'success' | 'info' | 'warning' | 'error'
  method(row: Row): void
}

export function createColumns(options: Operate[]): any[] {
  return [
    {
      type: 'selection',
      fixed: 'left'
    },

    {
      title: () => h('span', {}, '采购订单ID'),
      key: 'orderId',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '订单详情ID'),
      key: 'detailId',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '订单创建日期'),
      key: 'orderDate',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '产品名称'),
      key: 'productName',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '产品购买数量'),
      key: 'quantity',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '产品单价'),
      key: 'unitPrice',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '合计金额'),
      key: 'totalAmount',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '订单状态'),
      key: 'orderStatus',
      ellipsis: {
        tooltip: true
      },
      resizable: true
    },

    {
      title: () => h('span', {}, '操作'),
      key: 'options',
      resizable: true,
      fixed: 'right',
      render(row: Row) {
        const spans = options.map(v => {
          return h(
            NButton,
            {
              text: true,
              type: v.type || 'info',
              style: {
                marginRight: '10px'
              },
              onClick: () => v.method(row)
            },
            { default: () => (v.name) }
          )
        })
        return spans
      }
    }
  ]
}
